package bishi;

/**
 * @author: 唐小尊
 * @email: 1171702529@qq.com
 * @cate: 2021/06/01 06:42
 */
public class Test2 {
    public static void main(String[] args) {
        System.out.println(test(new int[]{1, -10, 3, 10, -7, 7, 2, 5}));
    }
    public static int test(int[] nums){
        int max = Integer.MIN_VALUE;
        int sum = 0;
        int now = 0;
        for (int num : nums) {
            if (num < 0 && now > 1) {
                max = Math.max(sum, max);
            }
            sum += num;
            now++;
            if (sum < 0) {
                sum = 0;
                now = 0;
            }
        }
        if (now > 1) {
            max = Math.max(sum, max);
        }
        return max;
    }
}
